/*
 * MainView.java
 */
package gui;

import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;

/**
 * The application's main frame.
 */
public class MainView extends FrameView {

    /**
     *
     */
    public application.Captor captor;
    /**
     *
     */
    public DefaultTreeModel treeModel;
    /**
     *
     */
    public ListSelectionListener listSelectionListener;

    /**
     *
     * @param app
     */
    public MainView(SingleFrameApplication app) {
        super(app);
        captor = new application.Captor();
        captor.createTable();
        captor.setMatchCase(false);
        initComponents();
        init();
    }

    private void init() {
        listSelectionListener = new ListSelectionListener() {

            public void valueChanged(ListSelectionEvent e) {
                if (e.getValueIsAdjusting()) {
                    return;
                }
                int index = ((ListSelectionModel) e.getSource()).getMinSelectionIndex();
                if (index >= 0) {
                    int num = packetTable.convertRowIndexToModel(index);
                    ((DefaultTreeModel) jTree.getModel()).setRoot(captor.getRoot(num));
                    jTree.repaint();
                    hexTextArea.setText(captor.getHexPacketData(num));
                    hexTextArea.repaint();
                    ASCIITextArea.setText(captor.getASCIIPacketData(num));
                    ASCIITextArea.repaint();
                }
            }
        };
        packetTable.getSelectionModel().addListSelectionListener(listSelectionListener);
        String[] s = captor.getDeviceName();
        deviceComboBox.removeAllItems();
        for (int i = 0; i < s.length; i++) {
            this.deviceComboBox.addItem(s[i]);
        }
        treeModel = new DefaultTreeModel(new DefaultMutableTreeNode());
        jTree.setModel(treeModel);
        jTree.setRootVisible(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainFrame = new javax.swing.JFrame();
        mainPanel = new javax.swing.JPanel();
        buttonPanel = new javax.swing.JPanel();
        filterPanel = new javax.swing.JPanel();
        sourceCheckBox = new javax.swing.JCheckBox();
        destCheckBox = new javax.swing.JCheckBox();
        protocolComboBox = new javax.swing.JComboBox();
        protocolCheckBox = new javax.swing.JCheckBox();
        sourceTextField = new javax.swing.JTextField();
        destTextField = new javax.swing.JTextField();
        filePanel = new javax.swing.JPanel();
        openButton = new javax.swing.JButton();
        saveButton = new javax.swing.JButton();
        operationPanel = new javax.swing.JPanel();
        startButton = new javax.swing.JButton();
        stopButton = new javax.swing.JButton();
        clearButton = new javax.swing.JButton();
        filterButton = new javax.swing.JButton();
        findPanel = new javax.swing.JPanel();
        findTextField = new javax.swing.JTextField();
        caseCheckBox = new javax.swing.JCheckBox();
        findButton = new javax.swing.JButton();
        packetPanel = new javax.swing.JPanel();
        savePacketButton = new javax.swing.JButton();
        reassemblePacketButton = new javax.swing.JButton();
        tablePanel = new javax.swing.JScrollPane();
        packetTable = new javax.swing.JTable();
        informationPanel = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTree = new javax.swing.JTree();
        jScrollPane1 = new javax.swing.JScrollPane();
        hexTextArea = new javax.swing.JTextArea();
        jScrollPane3 = new javax.swing.JScrollPane();
        ASCIITextArea = new javax.swing.JTextArea();
        devicePanel = new javax.swing.JPanel();
        deviceComboBox = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();

        mainFrame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        mainFrame.setResizable(false);

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(gui.Main.class).getContext().getResourceMap(MainView.class);
        filterPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("filterPanel.border.title"))); // NOI18N

        sourceCheckBox.setText(resourceMap.getString("sourceCheckBox.text")); // NOI18N
        sourceCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sourceCheckBoxActionPerformed(evt);
            }
        });

        destCheckBox.setText(resourceMap.getString("destCheckBox.text")); // NOI18N
        destCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                destCheckBoxActionPerformed(evt);
            }
        });

        protocolComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[]{
            "ARP", "TCP", "UDP", "ICMP"
        }));
        protocolComboBox.setEnabled(false);
        protocolComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                protocolComboBoxActionPerformed(evt);
            }
        });

        protocolCheckBox.setText(resourceMap.getString("protocolCheckBox.text")); // NOI18N
        protocolCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                protocolCheckBoxActionPerformed(evt);
            }
        });

        sourceTextField.setEditable(false);
        sourceTextField.setText(resourceMap.getString("sourceTextField.text")); // NOI18N
        sourceTextField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                sourceTextFieldFocusLost(evt);
            }
        });

        destTextField.setEditable(false);
        destTextField.setText(resourceMap.getString("destTextField.text")); // NOI18N
        destTextField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                destTextFieldFocusLost(evt);
            }
        });

        javax.swing.GroupLayout filterPanelLayout = new javax.swing.GroupLayout(filterPanel);
        filterPanel.setLayout(filterPanelLayout);
        filterPanelLayout.setHorizontalGroup(
            filterPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(filterPanelLayout.createSequentialGroup()
                .addContainerGap(10, Short.MAX_VALUE)
                .addGroup(filterPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(sourceTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(destTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(protocolComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(filterPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(sourceCheckBox)
                    .addComponent(protocolCheckBox)
                    .addComponent(destCheckBox)))
        );
        filterPanelLayout.setVerticalGroup(
            filterPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(filterPanelLayout.createSequentialGroup()
                .addGroup(filterPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(sourceCheckBox)
                    .addComponent(sourceTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(filterPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(destCheckBox)
                    .addComponent(destTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(filterPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(protocolCheckBox)
                    .addComponent(protocolComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        filePanel.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("filePanel.border.title"))); // NOI18N

        openButton.setText(resourceMap.getString("openButton.text")); // NOI18N
        openButton.setFocusPainted(false);
        openButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        openButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openButtonActionPerformed(evt);
            }
        });

        saveButton.setText(resourceMap.getString("saveButton.text")); // NOI18N
        saveButton.setFocusPainted(false);
        saveButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout filePanelLayout = new javax.swing.GroupLayout(filePanel);
        filePanel.setLayout(filePanelLayout);
        filePanelLayout.setHorizontalGroup(
            filePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, filePanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(openButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(filePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(saveButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        filePanelLayout.setVerticalGroup(
            filePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(filePanelLayout.createSequentialGroup()
                .addComponent(openButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(saveButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        operationPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("operationPanel.border.title"))); // NOI18N

        startButton.setText(resourceMap.getString("startButton.text")); // NOI18N
        startButton.setFocusPainted(false);
        startButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        startButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startButtonActionPerformed(evt);
            }
        });

        stopButton.setText(resourceMap.getString("stopButton.text")); // NOI18N
        stopButton.setFocusPainted(false);
        stopButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        stopButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stopButtonActionPerformed(evt);
            }
        });

        clearButton.setText(resourceMap.getString("clearButton.text")); // NOI18N
        clearButton.setFocusPainted(false);
        clearButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        clearButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearButtonActionPerformed(evt);
            }
        });

        filterButton.setText(resourceMap.getString("filterButton.text")); // NOI18N
        filterButton.setFocusPainted(false);
        filterButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        filterButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                filterButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout operationPanelLayout = new javax.swing.GroupLayout(operationPanel);
        operationPanel.setLayout(operationPanelLayout);
        operationPanelLayout.setHorizontalGroup(
            operationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(operationPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(operationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(operationPanelLayout.createSequentialGroup()
                        .addComponent(startButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(stopButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(operationPanelLayout.createSequentialGroup()
                        .addComponent(clearButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(filterButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        operationPanelLayout.setVerticalGroup(
            operationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(operationPanelLayout.createSequentialGroup()
                .addGroup(operationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(startButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(stopButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(operationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(clearButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(filterButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        findPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("findPanel.border.title"))); // NOI18N

        findTextField.setText(resourceMap.getString("findTextField.text")); // NOI18N
        findTextField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                findTextFieldFocusLost(evt);
            }
        });

        caseCheckBox.setText(resourceMap.getString("caseCheckBox.text")); // NOI18N
        caseCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                caseCheckBoxActionPerformed(evt);
            }
        });

        findButton.setText(resourceMap.getString("findButton.text")); // NOI18N
        findButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                findButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout findPanelLayout = new javax.swing.GroupLayout(findPanel);
        findPanel.setLayout(findPanelLayout);
        findPanelLayout.setHorizontalGroup(
            findPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(findPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(findPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(findTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)
                    .addComponent(caseCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)
                    .addComponent(findButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE))
                .addContainerGap())
        );
        findPanelLayout.setVerticalGroup(
            findPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(findPanelLayout.createSequentialGroup()
                .addComponent(findTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(caseCheckBox)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
                .addComponent(findButton)
                .addContainerGap())
        );

        packetPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("packetPanel.border.title"))); // NOI18N

        savePacketButton.setText(resourceMap.getString("savePacketButton.text")); // NOI18N
        savePacketButton.setFocusPainted(false);
        savePacketButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        savePacketButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                savePacketButtonActionPerformed(evt);
            }
        });

        reassemblePacketButton.setText(resourceMap.getString("reassemblePacketButton.text")); // NOI18N
        reassemblePacketButton.setFocusPainted(false);
        reassemblePacketButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        reassemblePacketButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reassemblePacketButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout packetPanelLayout = new javax.swing.GroupLayout(packetPanel);
        packetPanel.setLayout(packetPanelLayout);
        packetPanelLayout.setHorizontalGroup(
            packetPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, packetPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(savePacketButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(packetPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(reassemblePacketButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        packetPanelLayout.setVerticalGroup(
            packetPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(packetPanelLayout.createSequentialGroup()
                .addComponent(savePacketButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(reassemblePacketButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout buttonPanelLayout = new javax.swing.GroupLayout(buttonPanel);
        buttonPanel.setLayout(buttonPanelLayout);
        buttonPanelLayout.setHorizontalGroup(
            buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(buttonPanelLayout.createSequentialGroup()
                .addComponent(filePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(operationPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(filterPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(findPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(packetPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(58, Short.MAX_VALUE))
        );
        buttonPanelLayout.setVerticalGroup(
            buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup()
                .addGroup(buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(packetPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(findPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(filterPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(operationPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(filePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(129, 129, 129))
        );

        packetTable.setModel(captor.getTable());
        packetTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tablePanel.setViewportView(packetTable);

        jScrollPane2.setViewportView(jTree);

        hexTextArea.setColumns(20);
        hexTextArea.setEditable(false);
        hexTextArea.setRows(5);
        jScrollPane1.setViewportView(hexTextArea);

        jScrollPane3.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

        ASCIITextArea.setColumns(20);
        ASCIITextArea.setEditable(false);
        ASCIITextArea.setRows(5);
        jScrollPane3.setViewportView(ASCIITextArea);

        javax.swing.GroupLayout informationPanelLayout = new javax.swing.GroupLayout(informationPanel);
        informationPanel.setLayout(informationPanelLayout);
        informationPanelLayout.setHorizontalGroup(
            informationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(informationPanelLayout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 318, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        informationPanelLayout.setVerticalGroup(
            informationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 198, Short.MAX_VALUE)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 198, Short.MAX_VALUE)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 198, Short.MAX_VALUE)
        );

        devicePanel.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("devicePanel.border.title"))); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N

        javax.swing.GroupLayout devicePanelLayout = new javax.swing.GroupLayout(devicePanel);
        devicePanel.setLayout(devicePanelLayout);
        devicePanelLayout.setHorizontalGroup(
            devicePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(devicePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(deviceComboBox, 0, 599, Short.MAX_VALUE)
                .addContainerGap())
        );
        devicePanelLayout.setVerticalGroup(
            devicePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, devicePanelLayout.createSequentialGroup()
                .addGroup(devicePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(deviceComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(informationPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(tablePanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 688, Short.MAX_VALUE)
                    .addComponent(buttonPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(devicePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(devicePanel, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tablePanel, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(informationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout mainFrameLayout = new javax.swing.GroupLayout(mainFrame.getContentPane());
        mainFrame.getContentPane().setLayout(mainFrameLayout);
        mainFrameLayout.setHorizontalGroup(
            mainFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainFrameLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(mainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        mainFrameLayout.setVerticalGroup(
            mainFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(mainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        setComponent(mainPanel);
    }// </editor-fold>//GEN-END:initComponents

private void stopButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopButtonActionPerformed
// TODO add your handling code here:
    captor.stopCapture();
}//GEN-LAST:event_stopButtonActionPerformed

private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearButtonActionPerformed
// TODO add your handling code here:
    captor.clearTable();
}//GEN-LAST:event_clearButtonActionPerformed

private void openButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openButtonActionPerformed
// TODO add your handling code here:
    JFileChooser chooser = new JFileChooser();
    FileNameExtensionFilter filter = new FileNameExtensionFilter(
            "Packets dump", "pcap", "cap");
    chooser.setFileFilter(filter);
    chooser.setDialogType(JFileChooser.OPEN_DIALOG);
    int returnVal = chooser.showOpenDialog(openButton);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        captor.clearTable();
        captor.loadPacketsFromFile(chooser.getSelectedFile().getPath());
    }
}//GEN-LAST:event_openButtonActionPerformed

private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
// TODO add your handling code here:
    if (captor.getTable().getRowCount() == 0) {
        JOptionPane.showMessageDialog(
                null,
                "No packets captured!");
    } else {
        JFileChooser chooser = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter(
                "Packets dump", "pcap", "cap");
        chooser.setFileFilter(filter);
        chooser.setDialogType(JFileChooser.SAVE_DIALOG);
        int returnVal = chooser.showSaveDialog(saveButton);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            captor.savePacketsToFile(chooser.getSelectedFile().getPath());
        }
    }
}//GEN-LAST:event_saveButtonActionPerformed

private void sourceCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sourceCheckBoxActionPerformed
// TODO add your handling code here:
    if (sourceTextField.isEditable()) {
        captor.setFilterSource(null);
        sourceTextField.setEditable(false);
    } else {
        captor.setFilterSource(sourceTextField.getText());
        sourceTextField.setEditable(true);
    }
}//GEN-LAST:event_sourceCheckBoxActionPerformed

private void destCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_destCheckBoxActionPerformed
// TODO add your handling code here:
    if (destTextField.isEditable()) {
        captor.setFilterDestination(null);
        destTextField.setEditable(false);
    } else {
        captor.setFilterDestination(destTextField.getText());
        destTextField.setEditable(true);
    }
}//GEN-LAST:event_destCheckBoxActionPerformed

private void protocolCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_protocolCheckBoxActionPerformed
// TODO add your handling code here:
    if (protocolComboBox.isEnabled()) {
        captor.setFilterProtocol(null);
        protocolComboBox.setEnabled(false);
    } else {
        captor.setFilterProtocol((String) protocolComboBox.getSelectedItem());
        protocolComboBox.setEnabled(true);
    }
}//GEN-LAST:event_protocolCheckBoxActionPerformed

private void protocolComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_protocolComboBoxActionPerformed
// TODO add your handling code here:
    captor.setFilterProtocol((String) protocolComboBox.getSelectedItem());
}//GEN-LAST:event_protocolComboBoxActionPerformed

private void sourceTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_sourceTextFieldFocusLost
// TODO add your handling code here:
    captor.setFilterSource(sourceTextField.getText());
}//GEN-LAST:event_sourceTextFieldFocusLost

private void destTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_destTextFieldFocusLost
// TODO add your handling code here:
    captor.setFilterDestination(destTextField.getText());
}//GEN-LAST:event_destTextFieldFocusLost

private void filterButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_filterButtonActionPerformed
// TODO add your handling code here:
    captor.filterChanged();
}//GEN-LAST:event_filterButtonActionPerformed

private void findTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_findTextFieldFocusLost
// TODO add your handling code here:
    captor.setFilterQuery(findTextField.getText());
}//GEN-LAST:event_findTextFieldFocusLost

private void findButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findButtonActionPerformed
// TODO add your handling code here:
    captor.filterChanged();
}//GEN-LAST:event_findButtonActionPerformed

private void caseCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_caseCheckBoxActionPerformed
// TODO add your handling code here:
    captor.setMatchCase(caseCheckBox.isSelected());
}//GEN-LAST:event_caseCheckBoxActionPerformed

private void savePacketButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_savePacketButtonActionPerformed
    // TODO add your handling code here:
    int n = packetTable.getSelectedRow();
    if (n == -1) {
        JOptionPane.showMessageDialog(
                null,
                "No packet selected!");
    } else {
        JFileChooser chooser = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter(
                "Text", "txt");
        chooser.setFileFilter(filter);
        chooser.setDialogType(JFileChooser.SAVE_DIALOG);
        int returnVal = chooser.showSaveDialog(savePacketButton);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            captor.savePacket(chooser.getSelectedFile().getPath(), n);
        }
    }
}//GEN-LAST:event_savePacketButtonActionPerformed

private void reassemblePacketButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reassemblePacketButtonActionPerformed
    // TODO add your handling code here:
    int n = packetTable.getSelectedRow();
    if (n == -1) {
        JOptionPane.showMessageDialog(
                null,
                "No packet selected!");
    } else {
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogType(JFileChooser.SAVE_DIALOG);
        int returnVal = chooser.showSaveDialog(reassemblePacketButton);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            captor.reassemblePacket(chooser.getSelectedFile().getPath(), n);
        }
    }
}//GEN-LAST:event_reassemblePacketButtonActionPerformed

    private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
        packetTable.setModel(captor.getTable());
        captor.captureFromDevice(this.deviceComboBox.getSelectedIndex());
        captor.startCapture();
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea ASCIITextArea;
    private javax.swing.JPanel buttonPanel;
    private javax.swing.JCheckBox caseCheckBox;
    private javax.swing.JButton clearButton;
    private javax.swing.JCheckBox destCheckBox;
    private javax.swing.JTextField destTextField;
    private javax.swing.JComboBox deviceComboBox;
    private javax.swing.JPanel devicePanel;
    private javax.swing.JPanel filePanel;
    private javax.swing.JButton filterButton;
    private javax.swing.JPanel filterPanel;
    private javax.swing.JButton findButton;
    private javax.swing.JPanel findPanel;
    private javax.swing.JTextField findTextField;
    private javax.swing.JTextArea hexTextArea;
    private javax.swing.JPanel informationPanel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTree jTree;
    private javax.swing.JFrame mainFrame;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JButton openButton;
    private javax.swing.JPanel operationPanel;
    private javax.swing.JPanel packetPanel;
    private javax.swing.JTable packetTable;
    private javax.swing.JCheckBox protocolCheckBox;
    private javax.swing.JComboBox protocolComboBox;
    private javax.swing.JButton reassemblePacketButton;
    private javax.swing.JButton saveButton;
    private javax.swing.JButton savePacketButton;
    private javax.swing.JCheckBox sourceCheckBox;
    private javax.swing.JTextField sourceTextField;
    private javax.swing.JButton startButton;
    private javax.swing.JButton stopButton;
    private javax.swing.JScrollPane tablePanel;
    // End of variables declaration//GEN-END:variables
}
